// 云函数入口文件
const cloud = require('wx-server-sdk')

const axios = require('axios')


cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})


// 云函数入口函数
exports.main = async (event, context) => {
  let apiKey = 'z2H0YaLQv9RW6aepsBEGxRht',
  grantType = 'client_credentials',
  secretKey  = 'hulbODvRZvjhRw7Azy06KSzUdbM3EDke',
  oAuthUrl = `https://openapi.baidu.com/oauth/2.0/token?grant_type=${grantType}&client_id=${apiKey}&client_secret=${secretKey}`,
  accessTokenData = {}
  try {
    let { data } = await axios.get(oAuthUrl)
    // console.log(data); 
    accessTokenData = data 
  } catch (error) {
    console.log(error);
  }
  return accessTokenData
}